﻿using CommunityToolkit.Mvvm.ComponentModel;
using MetaView.Ticket.Models.Pages;
using System.Windows.Media;
using Wpf.Ui.Abstractions.Controls;

namespace MetaView.Ticket.ViewModels.Pages
{
    public partial class DataPageViewModel : ObservableObject, INavigationAware
    {

        [ObservableProperty]
        public DataPageModel? dataPageModels;


        public DataPageViewModel()
        {
            DataPageModels = new();
            InitializeViewModel();
        }

        public void OnNavigatedTo()
        {
            if (!DataPageModels!.isInitialized)
                InitializeViewModel();
        }

        public void OnNavigatedFrom() { }


        public void InitializeViewModel()
        {
            var random = new Random();
            var colorCollection = new List<DataColor>();

            for (int i = 0; i < 8192; i++)
                colorCollection.Add(
                    new DataColor
                    {
                        Color = new SolidColorBrush(
                            Color.FromArgb(
                                (byte)200,
                                (byte)random.Next(0, 250),
                                (byte)random.Next(0, 250),
                                (byte)random.Next(0, 250)
                            )
                        )
                    }
                );

            DataPageModels!.Colors = colorCollection;

            DataPageModels.isInitialized = true;
        }

        public Task OnNavigatedToAsync()
        {
            return Task.CompletedTask;
        }

        public Task OnNavigatedFromAsync()
        {
            return Task.CompletedTask;
        }
    }
}
